package com.lantu.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.lantu.sys.entity.Student;
import com.lantu.sys.mapper.StudentMapper;
import com.lantu.sys.service.StudentService;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {
    @Override
    public IPage<Student> getStudentByOpr(Page<Student> pageParam, Student student) {

        QueryWrapper<Student> studentQueryWrapper =new QueryWrapper<>();
        if(!StringUtils.isEmpty(student.getName())){
            studentQueryWrapper.like("name",student.getName());
        }
        if(!StringUtils.isEmpty(student.getClazzName())){
            studentQueryWrapper.like("clazz_name",student.getClazzName());
        }

        studentQueryWrapper.orderByAsc("id");
        Page<Student> studentPage = baseMapper.selectPage(pageParam, studentQueryWrapper);
        return studentPage;
    }

    @Override
    public Student getStudentBuUid(Integer uid) {
        QueryWrapper<Student> studentQueryWrapper =new QueryWrapper<>();
        studentQueryWrapper.like("uid",uid);
        Student student1 = baseMapper.selectOne(studentQueryWrapper);
        return student1;
    }

    @Override
    public IPage<Student> getByClass(Page<Student> pageParam, Student student) {
        QueryWrapper<Student> studentQueryWrapper =new QueryWrapper<>();
        studentQueryWrapper.like("clazz_name","九年级");
        studentQueryWrapper.orderByAsc("id");
        Page<Student> studentPage = baseMapper.selectPage(pageParam, studentQueryWrapper);
        return studentPage;
    }

    @Override
    public List<Student> getClassList() {
        QueryWrapper<Student> studentQueryWrapper = new QueryWrapper<>();
        studentQueryWrapper.select("DISTINCT clazz_name");
        return baseMapper.selectList(studentQueryWrapper);
    }

}
